package com.tr.rentcar.controller.houtai.car;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.tr.rentcar.model.bean.CarBrand;
import com.tr.rentcar.model.bean.CarUse;
import com.tr.rentcar.model.dao.CarBrandDao;
import com.tr.rentcar.model.dao.CarUseDao;
@WebServlet("/houtaicarbrand")
public class CarBrandControllor extends HttpServlet {
	CarBrandDao carbranddao=new CarBrandDao();
	CarBrand carbrand=new CarBrand();
	CarUse CarUse=new CarUse();
	CarUseDao CarUseDao=new CarUseDao();
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			
			List<CarBrand> carbrand=carbranddao.getAll();
			req.getSession().setAttribute("carbrand", carbrand);
			List<CarUse> CarUse=CarUseDao.getAll();
			req.getSession().setAttribute("CarUse", CarUse);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		req.getRequestDispatcher("/WEB-INF/jsp/houtai_carbrand.jsp").forward(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {req.setCharacterEncoding("utf-8");
		resp.setContentType("application/json;charset=utf-8");
			List<CarBrand> carbrand=carbranddao.getAll();
			PrintWriter out=resp.getWriter();
			out.print(JSONArray.toJSONString(carbrand));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
